<template>
	<!-- 参考链接：https://uniapp.dcloud.net.cn/api/request/request.html -->
	<view style="display: grid;grid-template-columns: 1fr 1fr">
		<button @click="getRequest">getRequest</button>
		
		<button @click="upload">upload</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				
			}
		},
		methods: {
			getRequest() {
				uni.request({
					url: "http://localhost:8080/hello",
					data: {"name":"hahah"},
					method:'GET',
					header:{}
				}).then((res) => {
					console.log("result:", JSON.stringify(res))
				}).catch((e) => {
					console.log("error:", JSON.stringify(e))
				})
			},
			upload() {
				uni.chooseImage({
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						uni.uploadFile({
							url: 'http://192.168.1.101:8090/uploadFile', //仅为示例，非真实的接口地址
							filePath: tempFilePaths[0],
							name: 'file',
							formData: {
								'enctype': 'multipart/form-data'
							},
							method: "POST",
							success: (uploadFileRes) => {
								console.log(uploadFileRes.data);
							}
						});
					}
				});

			}
		}
	}
</script>

<style>

</style>
